Field of the Disclosure
The present disclosure relates to an image processing method using pattern matching, an image processing apparatus, a program, a storage medium, a production apparatus, and a method of producing an assembly.
Description of the Related Art
In the field of image processing technology, it is well known to use pattern matching as a method of detecting a position of an object to be detected.
A conventional basic method of pattern matching is described below. To perform pattern matching, first, it is necessary to acquire reference information about an object to be detected. The reference information is generally called a model or a template. As for the reference information, a reference image is prepared by taking an image of an object in an ideal state (a reference object). An area including the object to be detected and a vicinity thereof is extracted from the reference image and is employed as a model or a template. In an actual process of detecting an object, a target object image is acquired by taking an image of an object, and a degree of similarity to the model or the template is calculated at each of various positions in the target object image. A position at which a highest degree of similarity is found is regarded as a detected position. That is, among positions in the target object image, a position at which a highest degree of similarity is obtained is searched for. However, the pattern matching needs a high calculation cost and a long processing time. Thus, to increase the processing speed, a pyramid search technique is generally used.
In the pyramid search method, an image is reduced a plurality of times in a step-by-step manner. First, pattern matching is performed on an image with a highest reduction ratio. Next, searching is performed on an image with a next highest reduction ratio but only in an area in the vicinity of the position at which the target object is detected in the previous image. By performing the search in the above-described manner repeatedly until the search is completed for an image with no reduction, it is possible to achieve an increase in the processing speed while maintaining the accuracy.
To calculate the degree of similarity described above, a plurality of methods are known. Examples include a sum of absolute difference (SAD) method, a normalized cross correlation (NCC) method, and a shape pattern matching method. Among various methods, the shape pattern matching method is robust against a change in illumination or against being partially hidden or lost, or the like. In the shape pattern matching method, the degree of similarity between a template and a target object image is calculated based on their shape features. Therefore, in the shape pattern matching method, it is necessary to extract a shape feature of an image.
To extract a shape feature, it is generally known to extract edges using a Sobel filter, a Canny filter, or the like. For each edge point obtained via the edge extraction process, information in terms of position coordinates, an intensity gradient direction, an intensity gradient magnitude, or the like is acquired. The pattern matching is performed while making a comparison between the template and the target object image in terms of the gradient direction at each edge point (hereinafter, referred to as an edge direction). If the difference in the edge direction between the template and the target object image is small at each edge point, it is determined that the template and the target object image have similar shape features and thus their degree of similarity is high. If the difference is large, the degree of similarity is low. That is, this method searches, from the target object image, for an image having edge directions similar to edge directions the template has, at edge position coordinates similar to edge position coordinates in the template.
However, there is a possibility that the detection target object has a partial change in terms of the edge direction due to adhesion of dust, dirt, or the like, a change in illumination, an object-to-object difference in surface state, or the like. In such a situation, when the edge directions are compared in the pattern matching, the resultant degree of similarity becomes extremely low, which may cause a recognition error to occur in searching the search target object.
In a method disclosed in Japanese Patent Laid-Open No. 2002-157591, to handle the above-described situation, in a case where an inversion in the edge direction by nearly 180° is found at some edge points, the degree of similarity is increased. That is, by neglecting the polarity of the edge direction in the calculation of the degree of similarity, it is possible to perform the pattern matching successfully without having a recognition error even in the above-described situation.
However, in the pattern matching method disclosed in Japanese Patent Laid-Open No. 2002-157591, the degree of similarity is increased by changing the edge direction into an opposite direction, and thus there is a tendency that the degree of similarity is increased at a position other than the target object. In the pyramid search, when reduced images in middle pyramid layers are subjected to searching, positions at which the degree of similarity (the score) is higher than a certain level are kept as matching candidate point for use in searching in a next pyramid level because there is a possibility that a recognition error occurs in searching in an image with a low resolution. In the pattern matching method disclosed in Japanese Patent Laid-Open No. 2002-157591, therefore, a large number of matching candidate points occur in searching at an initial stage or searching in middle pyramid layers, which results in an increase in processing time.
In view of the above, the present invention provides a technique of performing searching process on an image of a search target object (target object) such that the processing time is reduced while preventing a recognition error even in a situation in which an inversion of the edge direction occurs at some of points due to adhesion of dust, dirt, or the like, a change in illumination, an object-to-object difference in surface state, or the like.